<template>
  <div class="photoinfo-container">
    <h3>{{photoinfo.title}}</h3>
    <p class="subtitle">
      <span>发表时间:{{photoinfo.add_time|timeFormat}}</span>
      <span>点击{{photoinfo.click}}数</span>
    </p>
    <hr>
    <!-- 缩略图 -->
    <vue-preview
      :list="list"
      :thumbImageStyle="{width: '80px', height: '80px', margin: '10px'}"
      :previewBoxStyle="{border: '1px solid #eee'}"
      :tapToClose="true"
    />
    <!-- 图片内容区域 -->
    <div class="content" v-html="photoinfo.content"></div>
    <!--评论子组件 -->
    <cmt-box :parentId="id"></cmt-box>
  </div>
</template>
<script>
import comment from "../subcompents/comment";
export default {
  data() {
    return {
      id: this.$route.params.id,
      photoinfo: {},
      list: [] //缩略图数组
    };
  },
  methods: {
    getPhoteInfo() {
      this.$http.get("api/getimageInfo/" + this.id).then(function(res) {
        if (res.body.status !== 0) {
          return; //失败处理
        }
        this.photoinfo = res.body.message[0]; //取出数组里面唯一的{}
      });
    },
    getThumbs() {
      this.$http.get("api/getthumimages/" + this.id).then(function(res) {
        if (res.body.status !== 0) {
          return; //失败处理
        }
        
        // foreach每每个对象增加属性 foreach改变原来数组
        res.body.message.forEach(element => {
          element.w = 600;
          element.h = 400;
          element.msrc = element.src;
        });
        this.list = res.body.message;
        console.log(this.list);
      });
    },
   
  },
  components: {
    "cmt-box": comment
  },
  created() {
    this.getPhoteInfo();
    this.getThumbs();
  }
};
</script>   
<style lang="scss" scoped>
.photoinfo-container {
  padding: 5px h3 {
    color: #26a2ff;
    font-size: 15px;
    text-align: center;
    margin: 10px 0;
  }
  .subtitle {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
  }
  .content {
    line-height: 30px;
    font-size: 13px;
  }
}
</style>
